local skynet = require "skynet"
local filelog = require "filelog"

require "hbslenum"

local server = nil
local seatlogic = {}

function seatlogic.init(service)
	if server == nil then server = service end
end

function seatlogic.initseat(seatobj, index)
	seatobj.index = index
    seatobj.state = HBSLSeatState.SEAT_STATE_NO_PLAYER
end

function seatlogic.is_empty(seatobj)
    return (seatobj.state == HBSLSeatState.SEAT_STATE_NO_PLAYER)
end


function seatlogic.resetstate(seatobj)
	if seatobj == nil then return end
	local table_data = server.table_data
	seatobj.state = HBSLSeatState.SEAT_STATE_PLAYING
	seatobj.timer_id = -1
	seatobj.win = 0										---表示玩家胜利还是失败
	seatobj.balance_score = 0	 						----最终结算分数
	seatobj.dealnum = 0
	seatobj.action_to_time = 0							----操作超时时间
	seatobj.dealnum = 0 		 						----玩家中间结算量
	seatobj.next_leave = false
	seatobj.all_qhb_num = 0
	seatobj.all_qhb_money = 0
	seatobj.recent_qhb_infos = {}
end

function seatlogic.clear_seat(seatobj)
	seatobj.rid = 0
	seatobj.state = HBSLSeatState.SEAT_STATE_NO_PLAYER
	seatobj.agent_address = -1
	seatobj.playerinfo.rolename=""
	seatobj.playerinfo.logo=""
	seatobj.playerinfo.sex=0
	seatobj.playerinfo.ip=""
	seatobj.playerinfo.adress_gps = 1
	seatobj.playerinfo.gps_addr = ""
	seatobj.playerinfo.ip_address = ""
	seatobj.playerinfo.diamond = 0
	seatobj.playerinfo.fangka = 0
	seatobj.playerinfo.coin = 0
	seatobj.playerinfo.intro = ""
	seatobj.playerinfo.upvoted_num = 0
	seatobj.playerinfo.downvoted_num = 0
	seatobj.playerinfo.logoframe = 0
	seatobj.is_robot = false		--是否是机器人
	seatobj.next_leave = false
	seatobj.will_action = 0
	seatobj.action_type = 0
	seatobj.timer_id = 0			--定时器
	seatobj.action_to_time = 0	--操作超时时间
	seatobj.cancel_timerid = -1	 --解散牌桌定时器
	seatobj.timeout_count = 0		---玩家操作超时次数
	seatobj.win = 0				---记录玩家这局游戏的输赢
	seatobj.diamond = 0			----钻石(又叫元宝,用于元宝场)
	seatobj.is_disconnected = 0 ----玩家是否断线
	seatobj.balance_score = 0	 ----最终结算分数
	seatobj.dealnum = 0 		 ----玩家中间结算量
	seatobj.balance_total = 0	 ----自从进桌以来的总输赢
	seatobj.all_qhb_num = 0
	seatobj.all_qhb_money = 0
	seatobj.recent_qhb_infos = {}
end

function seatlogic.copy_last_playergethbs(seatobj, last_playergethbs)
	if seatobj == nil then return end
	local table_data = server.table_data
	--[[
	//最近抢到的红包
message lastplayergethb {
	optional int32  index 				= 1;
	optional int32  rid  				= 2; //抢红包玩家rid
	optional int32  hb_index 			= 3; //
	optional int32  hb_total_money 		= 4; // 红包总金额
	optional int32 	hb_nums				= 5; // 红包个数
	optional int32	qiang_hb_money		= 6; // 抢到的金额
	optional int32  get_hb_money   		= 7; // 实际得到的红包的钱
	optional string bury_hb_playername  = 8; // 发红包玩家名字
	optional int32  is_landmine 		= 9; // 是否中雷 (1 中雷 2 不中)
}
	--]]
	for index, qhb_get_info in ipairs(seatobj.recent_qhb_infos) do
		local recent_base = {
			index = index,
			rid = qhb_get_info.rid,
			hb_index = qhb_get_info.hb_index,
			hb_total_money = qhb_get_info.hb_total_money,
			hb_nums = qhb_get_info.hb_nums,
			qiang_hb_money = qhb_get_info.qiang_hb_money,
			get_hb_money = qhb_get_info.get_hb_money,
			bury_hb_playername = qhb_get_info.bury_hb_playername,
			is_landmine = qhb_get_info.is_landmine,
		}
		table.insert(last_playergethbs, recent_base)
	end
end

return seatlogic

